/*
 * @Descripttion:
 * @version:
 * @Author: lfzxs@qq.com
 * @Date: 2022-10-12 14:22:35
 * @LastEditors: lfzxs@qq.com
 * @LastEditTime: 2022-11-29 13:43:19
 */
package types

import (
	"fmt"
	"strings"
	"time"
)

const (
	MaxFileSize = 9223372036854775807
)

// Pair will store option for storage service.
type Pair struct {
	Key   string      `json:"key"`
	Value interface{} `json:"value"`
}

func (p Pair) String() string {
	return fmt.Sprintf("%s: %v", p.Key, p.Value)
}

func (p Pair) Int64() (int64,bool) {
	result,ok := p.Value.(int64)
	return result,ok
}

func Find(key string, pairs []Pair) (p *Pair, has bool) {
	for _, val := range pairs {
		if strings.EqualFold(val.Key, key) {
			return &val, true
		}
	}

	return nil, false
}

func WithSize(v int64) (p Pair) {
	return Pair{Key: "size", Value: v}
}

// WithContentMd5 will apply content_md5 value to Options.
//
// ContentMd5
func WithContentMd5(v string) (p Pair) {
	return Pair{Key: "content_md5", Value: v}
}

// WithContentType will apply content_type value to Options.
//
// ContentType
func WithContentType(v string) (p Pair) {
	return Pair{Key: "content_type", Value: v}
}

// WithContentType will apply content_type value to Options.
//
// ContentType
func WithModifyTime(v time.Time) (p Pair) {
	return Pair{Key: "modify_time", Value: v}
}
func WithPath(v string) (p Pair) {
	return Pair{Key: "path", Value: v}
}
